package com.hua.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hua.common.Response;
import com.hua.common.ResponseCode;
import com.hua.domain.Teabottom;
import com.hua.exception.BusinessException;
import com.hua.mapper.TeabottomMapper;
import com.hua.service.TeabottomService;
import com.hua.util.ResultUtils;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Distance
 * @description 针对表【teabottom(茶底表)】的数据库操作Service实现
 * @createDate 2022-10-19 19:13:26
 */
@Service
public class TeabottomServiceImpl extends ServiceImpl<TeabottomMapper, Teabottom> implements TeabottomService {

    @Resource
    private TeabottomMapper teabottomMapper;

    @Override
    public Response<List<Teabottom>> getAll() {
        List<Teabottom> teabottoms = teabottomMapper.selectList(null);
        return new Response<List<Teabottom>>(200, teabottoms, "返回所有茶底");
    }

    @Override
    public Response<String> updateTeabottomById(Teabottom teabottom) {
        int result = teabottomMapper.updateById(teabottom);
        if (result > 0) {
            return ResultUtils.success(ResponseCode.SUCCESS, "更新成功");
        }
        throw new BusinessException(ResponseCode.UPDATE_ERROR, "更新失败");

    }

    @Override
    public Response<String> insertTeaBottom(Teabottom teabottom) {

        teabottom.setIsHave(0);
        int result = teabottomMapper.insert(teabottom);
        if (result > 0) {
            return ResultUtils.success(ResponseCode.SUCCESS, "更新成功");
        }
        throw new BusinessException(ResponseCode.UPDATE_ERROR, "更新失败");
    }

    @Override
    public Response<String> deleteTeaBottomById(Integer teaId) {
        int result = teabottomMapper.deleteById(teaId);
        if (result > 0) {
            return ResultUtils.success(ResponseCode.SUCCESS, "更新成功");
        }
        throw new BusinessException(ResponseCode.UPDATE_ERROR, "更新失败");
    }
}




